// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
// import FastClick from 'fastclick';
import VueRouter from 'vue-router';
import App from './App';
import router from './router';
import axios from 'axios';
import { setUserInfo, getUserInfo, setTypeKeyValue, getTypeKeyValue, getTypeKeyValueFromKeyId, getRequestUrl } from '@/assets/js/wechat.js';

Vue.prototype.getRequestUrl = getRequestUrl;
Vue.prototype.setUserInfo = setUserInfo;
Vue.prototype.getUserInfo = getUserInfo;
Vue.prototype.setTypeKeyValue = setTypeKeyValue;
Vue.prototype.getTypeKeyValue = getTypeKeyValue;
Vue.prototype.getTypeKeyValueFromKeyId = getTypeKeyValueFromKeyId;

Vue.use(VueRouter);

// Vue.use(vueg, router);

// FastClick.attach(document.body);

axios.interceptors.response.use(
  (response) => {
    return response;
  },
  (error) => {
  if (error.message.includes('timeout')) {   // 判断请求异常信息中是否含有超时timeout字符串
    alert('網絡超時，請稍後重試！');
    return Promise.reject(error);          // reject这个错误信息
  }
  return Promise.reject(error);
});

Vue.config.productionTip = false;

// localhost
// axios.defaults.baseURL = 'http://localhost:56776/api';
// test
// axios.defaults.baseURL = 'http://10.68.2.9/Process/api';
// 正式
// axios.defaults.baseURL = 'http://mo.centanet.com/ProcessApi/api';

axios.defaults.timeout = 20000;
Vue.prototype.axios = axios;

/* eslint-disable no-new */
new Vue({
  router,
  render: h => h(App)
}).$mount('#app-box');
